package com.sskj.level.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.level.bean.TradeListBean;
import com.sskj.level.http.HttpConfig;
import com.sskj.level.ui.fragment.CurrentEntrustFragment;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.CallBackOption;

import java.util.ArrayList;


public class CurrentHolderFragmentPresenter extends BasePresenter<CurrentEntrustFragment> {

    public void getTradeList(String code, String pageNum, String pageSize) {
        httpService.getWeituo(code, pageNum, pageSize)
                .tag(this)
                .execute(new CallBackOption<HttpData<PageBean<TradeListBean>>>() {
                    @Override
                    public void onError(Response<HttpData<PageBean<TradeListBean>>> response) {
                        super.onError(response);
                        mView.updateUI(new ArrayList<>());
                    }
                }
                        .loadBind(mView)
                        .execute(httpData -> {
                            if (httpData.getStatus() == HttpConfig.OK) {
                                mView.updateUI(httpData.getData().getList());
                            }
                        }));
    }

    public void cancelOrder(String orderId) {
        httpService.cancelOrder(orderId)
                .execute(new CallBackOption<HttpData>() {
                }
                        .loadBind(mView)
                        .execute(httpData -> {
                            ToastUtil.showShort(httpData.getMsg());
                            if (httpData.getStatus() == HttpConfig.OK) {
                                mView.cancelOrderSuccess();
                            }
                        }));
    }
}
